import { connect, model } from "mongoose";
import { mongoPath } from "../config/config.default.js";
import userSchema from "./userModel.js";
import videoSchema from "./videoModel.js";
import followSchema from "./followModel.js";
import commentSchema from "./commentModel.js";
import videoLikeSchema from "./videoLikeModel.js";
import videoCollectSchema from "./videoCollectModel.js";
import chatMessageSchema from "./chatMessageModel.js";
import chatRoomSchema from "./chatRoom.js";
import roomMessageSchema from "./roomMessage.js";
// 数据库连接
async function connectDatabase() {
  try {
    await connect(mongoPath);
    console.log("数据库连接成功");
  } catch (err) {
    console.error(err);
    console.error("数据库连接失败");
    process.exit(1); // 如果连接失败，退出进程
  }
}
connectDatabase();
// 导出模型
export const User = model("User", userSchema);
export const Video = model("Video", videoSchema);
export const Follow = model("Follow", followSchema);
export const Comment = model("Comment", commentSchema);
export const VideoLike = model("VideoLike", videoLikeSchema);
export const VideoCollect = model("VideoCollect", videoCollectSchema);
export const ChatMessage = model("ChatMessage", chatMessageSchema);
export const ChatRoom = model("ChatRoom", chatRoomSchema);
export const RoomMessage = model("RoomMessage", roomMessageSchema);
